home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / redalert.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  11KB  |  370 lines

  1. /***************************************************************************
  2.  
  3. Irem Red Alert Driver
  4.  
  5. Everything in this driver is guesswork and speculation.  If something
  6. seems wrong, it probably is.
  7.  
  8. If you have any questions about how this driver works, don't hesitate to
  9. ask.  - Mike Balfour (mab22@po.cwru.edu)
  10. ***************************************************************************/
  11.  
  12. #include "driver.h"
  13. #include "vidhrdw/generic.h"
  14.  
  15. /* vidhrdw/redalert.c */
  16. extern unsigned char *redalert_backram;
  17. extern unsigned char *redalert_spriteram1;
  18. extern unsigned char *redalert_spriteram2;
  19. extern unsigned char *redalert_characterram;
  20. WRITE_HANDLER( redalert_backram_w );
  21. WRITE_HANDLER( redalert_spriteram1_w );
  22. WRITE_HANDLER( redalert_spriteram2_w );
  23. WRITE_HANDLER( redalert_characterram_w );
  24. extern void redalert_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  25. WRITE_HANDLER( redalert_c040_w );
  26. WRITE_HANDLER( redalert_backcolor_w );
  27.  
  28. /* sndhrdw/redalert.c */
  29. WRITE_HANDLER( redalert_c030_w );
  30. READ_HANDLER( redalert_voicecommand_r );
  31. WRITE_HANDLER( redalert_soundlatch_w );
  32. READ_HANDLER( redalert_AY8910_A_r );
  33. WRITE_HANDLER( redalert_AY8910_B_w );
  34. WRITE_HANDLER( redalert_AY8910_w );
  35. READ_HANDLER( redalert_sound_register_IC1_r );
  36. WRITE_HANDLER( redalert_sound_register_IC2_w );
  37.  
  38.  
  39. static struct MemoryReadAddress readmem[] =
  40. {
  41.     { 0x0000, 0x01ff, MRA_RAM }, /* Zero page / stack */
  42.     { 0x0200, 0x0fff, MRA_RAM }, /* ? */
  43.     { 0x1000, 0x1fff, MRA_RAM }, /* Scratchpad video RAM */
  44.     { 0x2000, 0x4fff, MRA_RAM }, /* Video RAM */
  45.     { 0x5000, 0xbfff, MRA_ROM },
  46.     { 0xc100, 0xc100, input_port_0_r },
  47.     { 0xc110, 0xc110, input_port_1_r },
  48.     { 0xc120, 0xc120, input_port_2_r },
  49.     { 0xc170, 0xc170, input_port_3_r }, /* Vertical Counter? */
  50.     { 0xf000, 0xffff, MRA_ROM }, /* remapped ROM for 6502 vectors */
  51.     { -1 }    /* end of table */
  52. };
  53.  
  54. static struct MemoryWriteAddress writemem[] =
  55. {
  56.     { 0x0000, 0x01ff, MWA_RAM },
  57.     { 0x0200, 0x0fff, MWA_RAM }, /* ? */
  58.     { 0x1000, 0x1fff, MWA_RAM }, /* Scratchpad video RAM */
  59.     { 0x2000, 0x3fff, redalert_backram_w, &redalert_backram },
  60.     { 0x4000, 0x43ff, videoram_w, &videoram, &videoram_size },
  61.     { 0x4400, 0x47ff, redalert_spriteram1_w, &redalert_spriteram1 },
  62.     { 0x4800, 0x4bff, redalert_characterram_w, &redalert_characterram },
  63.     { 0x4c00, 0x4fff, redalert_spriteram2_w, &redalert_spriteram2 },
  64.     { 0x5000, 0xbfff, MWA_ROM },
  65.     { 0xc130, 0xc130, redalert_c030_w },
  66. //    { 0xc140, 0xc140, redalert_c040_w }, /* Output port? */
  67.     { 0xc150, 0xc150, redalert_backcolor_w },
  68.     { 0xc160, 0xc160, redalert_soundlatch_w },
  69.     { 0xf000, 0xffff, MWA_ROM },
  70.     { -1 }    /* end of table */
  71. };
  72.  
  73. static struct MemoryReadAddress sound_readmem[] =
  74. {
  75.     { 0x0000, 0x03ff, MRA_RAM },
  76.     { 0x7800, 0x7fff, MRA_ROM },
  77.     { 0xf800, 0xffff, MRA_ROM },
  78.     { 0x1001, 0x1001, redalert_sound_register_IC1_r },
  79.     { -1 }  /* end of table */
  80. };
  81.  
  82. static struct MemoryWriteAddress sound_writemem[] =
  83. {
  84.     { 0x0000, 0x03ff, MWA_RAM },
  85.     { 0x7800, 0x7fff, MWA_ROM },
  86.     { 0xf800, 0xffff, MWA_ROM },
  87.     { 0x1000, 0x1000, redalert_AY8910_w },
  88.     { 0x1001, 0x1001, redalert_sound_register_IC2_w },
  89.     { -1 }  /* end of table */
  90. };
  91.  
  92. static struct MemoryReadAddress voice_readmem[] =
  93. {
  94.     { 0x0000, 0x3fff, MRA_ROM },
  95.     { 0x8000, 0x83ff, MRA_RAM },
  96. //    { 0xc000, 0xc000, redalert_voicecommand_r }, /* reads command from D0-D5? */
  97.     { -1 }  /* end of table */
  98. };
  99.  
  100. static struct MemoryWriteAddress voice_writemem[] =
  101. {
  102.     { 0x0000, 0x3fff, MWA_ROM },
  103.     { 0x8000, 0x83ff, MWA_RAM },
  104.     { -1 }  /* end of table */
  105. };
  106.  
  107.  
  108. INPUT_PORTS_START( redalert )
  109.     PORT_START               /* DIP Switches */
  110.     PORT_DIPNAME( 0x03, 0x00, DEF_STR( Lives ) )
  111.     PORT_DIPSETTING(    0x00, "3" )
  112.     PORT_DIPSETTING(    0x01, "4" )
  113.     PORT_DIPSETTING(    0x02, "5" )
  114.     PORT_DIPSETTING(    0x03, "6" )
  115.     PORT_DIPNAME( 0x04, 0x00, DEF_STR( Unknown ) )
  116.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  117.     PORT_DIPSETTING(    0x04, DEF_STR( On ) )
  118.     PORT_DIPNAME( 0x08, 0x00, DEF_STR( Bonus_Life ) )
  119.     PORT_DIPSETTING(    0x00, "5000" )
  120.     PORT_DIPSETTING(    0x08, "7000" )
  121.     PORT_DIPNAME( 0x30, 0x10, DEF_STR( Coinage ) )
  122.     PORT_DIPSETTING(    0x30, DEF_STR( 2C_1C ) )
  123.     PORT_DIPSETTING(    0x10, DEF_STR( 1C_1C ) )
  124.     PORT_DIPSETTING(    0x20, DEF_STR( 1C_2C ) )
  125.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
  126.     PORT_DIPNAME( 0x40, 0x00, DEF_STR( Unknown ) )
  127.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  128.     PORT_DIPSETTING(    0x40, DEF_STR( On ) )
  129.     PORT_SERVICE( 0x80, IP_ACTIVE_HIGH )
  130.  
  131.     PORT_START               /* IN1 */
  132.     PORT_BIT ( 0x01, IP_ACTIVE_HIGH, IPT_START1 )
  133.     PORT_BIT ( 0x02, IP_ACTIVE_HIGH, IPT_START2 )
  134.     PORT_BIT ( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON1 )
  135.     PORT_BIT ( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  136.     PORT_BIT ( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  137.     PORT_BIT ( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT )
  138.     PORT_BIT ( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT )
  139.     PORT_BIT ( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* Meter */
  140.  
  141.     PORT_START               /* IN2  */
  142.     PORT_BIT ( 0x01, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  143.     PORT_BIT ( 0x02, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* Meter */
  144.     PORT_BIT ( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON1 | IPF_PLAYER2 )
  145.     PORT_BIT ( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  146.     PORT_BIT ( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  147.     PORT_BIT ( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT | IPF_PLAYER2 )
  148.     PORT_BIT ( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT | IPF_PLAYER2 )
  149.     PORT_BIT ( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN ) /* Meter */
  150.  
  151.     PORT_START               /* IN3 - some type of video counter? */
  152.     PORT_BIT ( 0x01, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  153.     PORT_BIT ( 0x02, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  154.     PORT_BIT ( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  155.     PORT_BIT ( 0x08, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  156.     PORT_BIT ( 0x10, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  157.     PORT_BIT ( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  158.     PORT_BIT ( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  159.     PORT_BIT ( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  160.  
  161.     PORT_START               /* Fake input for coins */
  162.     PORT_BIT ( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
  163.     PORT_BIT ( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE )
  164. INPUT_PORTS_END
  165.  
  166.  
  167. static struct GfxLayout backlayout =
  168. {
  169.     8,8,    /* 8*8 characters */
  170.     0x400,      /* 1024 characters */
  171.     1,    /* 1 bits per pixel */
  172.     { 0 }, /* No info needed for bit offsets */
  173.     { 0, 1, 2, 3, 4, 5, 6, 7 },
  174.     { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
  175.     8*8 /* every char takes 8 consecutive bytes */
  176. };
  177.  
  178. static struct GfxLayout charlayout =
  179. {
  180.     8,8,    /* 8*8 characters */
  181.     128,    /* 128 characters */
  182.     1,    /* 1 bits per pixel */
  183.     { 0 }, /* No info needed for bit offsets */
  184.     { 0, 1, 2, 3, 4, 5, 6, 7 },
  185.     { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
  186.     8*8 /* every char takes 8 consecutive bytes */
  187. };
  188.  
  189. static struct GfxLayout spritelayout =
  190. {
  191.     8,8,    /* 8*8 characters */
  192.     128,    /* 128 characters */
  193.     2,        /* 1 bits per pixel */
  194.     { 0, 0x800*8 }, /* No info needed for bit offsets */
  195.     { 0, 1, 2, 3, 4, 5, 6, 7 },
  196.     { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
  197.     8*8 /* every char takes 8 consecutive bytes */
  198. };
  199.  
  200. static struct GfxDecodeInfo gfxdecodeinfo[] =
  201. {
  202.     { 0, 0x3000, &backlayout,    0, 8 },     /* the game dynamically modifies this */
  203.     { 0, 0x4800, &charlayout,    0, 8 },     /* the game dynamically modifies this */
  204.     { 0, 0x4400, &spritelayout,16, 4 },     /* the game dynamically modifies this */
  205.     { -1 } /* end of array */
  206. };
  207.  
  208. /* Arbitrary colors */
  209. static unsigned char palette[] =
  210. {
  211.     0x40,0x80,0xff,    /* Background */
  212.     0x00,0x00,0xff,    /* Blue */
  213.     0xff,0x00,0xff,    /* Magenta */
  214.     0x00,0xff,0xff,    /* Cyan */
  215.     0xff,0x00,0x00,    /* Red */
  216.     0xff,0x80,0x00,    /* Orange */
  217.     0xff,0xff,0x00,    /* Yellow */
  218.     0xff,0xff,0xff,    /* White */
  219.     0x00,0x00,0x00,    /* Black */
  220. };
  221.  
  222. /* Arbitrary colortable */
  223. static unsigned short colortable[] =
  224. {
  225.     0,7,
  226.     0,6,
  227.     0,2,
  228.     0,4,
  229.     0,3,
  230.     0,6,
  231.     0,1,
  232.     0,8,
  233.  
  234.     0,8,8,8,
  235.     0,6,4,7,
  236.     0,6,4,1,
  237.     0,8,5,1,
  238. };
  239.  
  240. static void init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
  241. {
  242.     memcpy(game_palette,palette,sizeof(palette));
  243.     memcpy(game_colortable,colortable,sizeof(colortable));
  244. }
  245.  
  246.  
  247.  
  248. static int redalert_interrupt(void)
  249. {
  250.     static int lastcoin = 0;
  251.     int newcoin;
  252.  
  253.     newcoin = input_port_4_r(0);
  254.  
  255.     if (newcoin)
  256.     {
  257.         if ((newcoin & 0x01) && !(lastcoin & 0x01))
  258.         {
  259.             lastcoin = newcoin;
  260.             return nmi_interrupt();
  261.         }
  262.         if ((newcoin & 0x02) && !(lastcoin & 0x02))
  263.         {
  264.             lastcoin = newcoin;
  265.             return nmi_interrupt();
  266.         }
  267.     }
  268.  
  269.     lastcoin = newcoin;
  270.     return interrupt();
  271. }
  272.  
  273. static struct AY8910interface ay8910_interface =
  274. {
  275.     1,            /* 1 chip */
  276.     2000000,    /* 2 MHz */
  277.     { 50 },        /* Volume */
  278.     { redalert_AY8910_A_r },        /* Port A Read */
  279.     { 0 },        /* Port B Read */
  280.     { 0 },        /* Port A Write */
  281.     { redalert_AY8910_B_w }        /* Port B Write */
  282. };
  283.  
  284.  
  285.  
  286. static struct MachineDriver machine_driver_redalert =
  287. {
  288.     /* basic machine hardware */
  289.     {
  290.         {
  291.             CPU_M6502,
  292.             1000000,       /* ???? */
  293.             readmem,writemem,0,0,
  294.             redalert_interrupt,1
  295.         },
  296.         {
  297.             CPU_M6502 | CPU_AUDIO_CPU,
  298.             1000000,       /* 1 MHz */
  299.             sound_readmem,sound_writemem,0,0,
  300.             /* IRQ is hooked to a 555 timer, whose freq is 1150 Hz */
  301.             0,0,
  302.             interrupt,1150
  303.         },
  304.         {
  305.             CPU_8085A | CPU_AUDIO_CPU,
  306.             1000000,       /* 1 MHz? */
  307.             voice_readmem,voice_writemem,0,0,
  308.             ignore_interrupt,1
  309.         }
  310.     },
  311.     60, DEFAULT_REAL_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  312.     1,      /* 1 CPU slice per frame - interleaving is forced when a sound command is written */
  313.     0,
  314.  
  315.     /* video hardware */
  316.     32*8, 32*8, { 0*8, 32*8-1, 1*8, 31*8-1 },
  317.     gfxdecodeinfo,
  318.     sizeof(palette) / sizeof(palette[0]) / 3, sizeof(colortable) / sizeof(colortable[0]),
  319.     init_palette,
  320.  
  321.     VIDEO_TYPE_RASTER,
  322.     0,
  323.     generic_vh_start,
  324.     generic_vh_stop,
  325.     redalert_vh_screenrefresh,
  326.  
  327.     /* sound hardware */
  328.     0,0,0,0,
  329.     {
  330.         {
  331.             SOUND_AY8910,
  332.             &ay8910_interface
  333.         }
  334.     }
  335.  
  336. };
  337.  
  338.  
  339. /***************************************************************************
  340.  
  341.   Game ROMs
  342.  
  343. ***************************************************************************/
  344.  
  345. ROM_START( redalert )
  346.     ROM_REGION( 0x10000, REGION_CPU1 ) /* 64k for code */
  347.     ROM_LOAD( "rag5",             0x5000, 0x1000, 0xd7c9cdd6 )
  348.     ROM_LOAD( "rag6",             0x6000, 0x1000, 0xcb2a308c )
  349.     ROM_LOAD( "rag7n",            0x7000, 0x1000, 0x82ab2dae )
  350.     ROM_LOAD( "rag8n",            0x8000, 0x1000, 0xb80eece9 )
  351.     ROM_RELOAD(                 0xf000, 0x1000 )
  352.     ROM_LOAD( "rag9",             0x9000, 0x1000, 0x2b7d1295 )
  353.     ROM_LOAD( "ragab",            0xa000, 0x1000, 0xab99f5ed )
  354.     ROM_LOAD( "ragb",             0xb000, 0x1000, 0x8e0d1661 )
  355.  
  356.     ROM_REGION( 0x10000, REGION_CPU2 ) /* 64k for code */
  357.     ROM_LOAD( "w3s1",             0x7800, 0x0800, 0x4af956a5 )
  358.     ROM_RELOAD(                0xf800, 0x0800 )
  359.  
  360.     ROM_REGION( 0x10000, REGION_CPU3 ) /* 64k for code */
  361.     ROM_LOAD( "ras1b",            0x0000, 0x1000, 0xec690845 )
  362.     ROM_LOAD( "ras2",             0x1000, 0x1000, 0xfae94cfc )
  363.     ROM_LOAD( "ras3",             0x2000, 0x1000, 0x20d56f3e )
  364.     ROM_LOAD( "ras4",             0x3000, 0x1000, 0x130e66db )
  365. ROM_END
  366.  
  367.  
  368.  
  369. GAMEX( 1981, redalert, 0, redalert, redalert, 0, ROT270, "GDI + Irem", "Red Alert", GAME_WRONG_COLORS | GAME_IMPERFECT_SOUND)
  370.